﻿using SysManage.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ZHDJ.Data.Models.Org;
using FineUI;
using ZHDJ.Core.Util;

namespace SysManage.Module.Org
{
    public partial class PartyOrgDutyEdit : PageBase
    {
        #region ViewPower
        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "PartyOrgBranchDutyAdd";
            }
        }
        #endregion

        #region 页面属性
        public string EditorContent = string.Empty;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            string _BranchID = GetQueryIntValue("BranchID");
            if (string.IsNullOrWhiteSpace(_BranchID))
            {
                Alert.Show("参数错误！", String.Empty);
                return;
            }
            //根据当前登录人获取数据
            PartyOrgDuty model = DB.PartyOrgDutys.Where(i => i.BranchID == _BranchID).FirstOrDefault();
            if (model != null)
                EditorContent = model.Content;
        }

        /// <summary>
        /// 保存并关闭按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            string _BranchID = GetQueryIntValue("BranchID");
            if (string.IsNullOrWhiteSpace(_BranchID))
            {
                Alert.Show("参数错误！", String.Empty);
                return;
            }
            PartyOrgDuty model = DB.PartyOrgDutys.Where(i => i.BranchID == BranchID).FirstOrDefault();

            if (model == null)
            {
                model = new PartyOrgDuty();
                model.ID = StringHelper.NewID;
                model.BranchID = _BranchID;
                model.Content = this.Request.Form["editorValue"];
                model.CreateTime = DateTime.Now;
                model.CreateBy = CurrentUser.LoginID;

                DB.PartyOrgDutys.Add(model);
            }
            else
            {
                model.Content = this.Request.Form["editorValue"];
            }

            DB.SaveChanges();
        }

    }
}